<div class="modal-header">
  <div class="modal-title">{{ record.ID > 0 ? '编辑 ' + record.username + ' 信息' : '新建' }}</div>
</div>
<nz-spin *ngIf="!i" class="modal-spin"></nz-spin>
<div *ngIf="i">
  <form nz-form [formGroup]="validateForm">
    <input nz-input hidden formControlName="ID" />
    <div nz-row [nzGutter]="24">
      <div nz-col [nzSpan]="20">
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzRequired nzFor="username">用户名</nz-form-label>
          <nz-form-control [nzSpan]="16" nzHasFeedback nzErrorTip="请填写用户名！">
            <input nz-input formControlName="username" placeholder="用户名，用于系统登录" />
          </nz-form-control>
        </nz-form-item>
      </div>

      <div nz-col [nzSpan]="20">
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="nickname">昵称</nz-form-label>
          <nz-form-control [nzSpan]="16">
            <input nz-input formControlName="nickname" placeholder="昵称" />
          </nz-form-control>
        </nz-form-item>
      </div>

      <div nz-col [nzSpan]="20" *ngIf="!i.ID">
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="password">密码</nz-form-label>
          <nz-form-control [nzSpan]="16" nzHasFeedback nzErrorTip="请填写密码！">
            <nz-input-group [nzSuffix]="suffixTemplate">
              <input
                formControlName="password"
                [type]="passwordVisible ? 'text' : 'password'"
                nz-input
                placeholder="登录密码"
                [(ngModel)]="password"
              />
            </nz-input-group>
            <ng-template #suffixTemplate>
              <i
                nz-icon
                [nzType]="passwordVisible ? 'eye-invisible' : 'eye'"
                (click)="passwordVisible = !passwordVisible"
                style="cursor: pointer"
              ></i>
            </ng-template>
          </nz-form-control>
        </nz-form-item>
      </div>

      <div nz-col [nzSpan]="20">
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="status">状态</nz-form-label>
          <nz-form-control [nzSpan]="16">
            <nz-radio-group formControlName="status">
              <label nz-radio [nzValue]="0">禁用</label>
              <label nz-radio [nzValue]="1">启用</label>
            </nz-radio-group>
          </nz-form-control>
        </nz-form-item>
      </div>

      <div nz-col [nzSpan]="20">
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="company_id">所属组织</nz-form-label>
          <nz-form-control [nzSpan]="16" nzErrorTip="请选择所属组织！">
            <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择所属组织" formControlName="company_id">
              <nz-option [nzLabel]="'无'" [nzValue]="0" [nzDisabled]="companyDefault != 0"></nz-option>
              <nz-option *ngFor="let c of companies" [nzLabel]="c['company_name']" [nzValue]="c['ID']"></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>
      </div>

      <div nz-col [nzSpan]="20">
        <nz-form-item>
          <nz-form-label [nzSpan]="8" nzFor="company_id">附属组织</nz-form-label>
          <nz-form-control [nzSpan]="16" nzErrorTip="请选择附属组织！">
            <nz-select nzShowSearch nzAllowClear nzMode="multiple" nzPlaceHolder="请选择附属组织" formControlName="ex_company_ids">
              <nz-option [nzLabel]="'无'" [nzValue]="0" [nzDisabled]="companyDefault != 0"></nz-option>
              <nz-option
                *ngFor="let c of companies"
                [nzLabel]="c['company_name']"
                [nzDisabled]="companyDefault == c['ID']"
                [nzValue]="c['ID']"
              ></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>
      </div>
    </div>
  </form>
</div>

<div class="modal-footer">
  <button nz-button type="button" (click)="close()">关闭</button>
  <button
    nz-button
    type="submit"
    nzType="primary"
    (click)="save(validateForm.value)"
    [disabled]="!validateForm.valid"
    [nzLoading]="http.loading"
    >保存
  </button>
</div>
